<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}lib/ja.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}text.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}enhanced.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}proxy/pae.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}custominput.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}text.js"></script>
<title>分派设备</title>
</head>
<script type="text/javascript">
	$(document).ready(function() {
		$("#entranceinfo")
				.jqGrid(
						{
							url : "${aier_url}${aier_urijs}proxy_assign_searchEntranceInfo${aier_suffix}?pid=${pid}",
							datatype : "json",
							mtype : 'GET',
							height : '230',
							width : '960',
							colNames : [ '设备编码', '状态','所属学校','设备厂家', '视频编码', '拍照状态','操作','门禁id' ],
							colModel : [ 
							{name : 'sn',index : 'sn',width : 80,align : 'center'}, 
							{name : 'state_str',index : 'state_str',width : 80,align : 'center',sortable:false}, 
							{name : 'school_name',index : 'school_name',width : 80,align : 'center',sortable:false}, 
							{name : 'supplier_str',index : 'supplier_str',width : 80,align : 'center',sortable:false}, 
							{name : 'video_sn',index : 'video_sn',width : 80,align : 'center',sortable:false}, 
							{name : 'vdstate_str',index : 'vdstate_str',width : 80,align : 'center',sortable:false}, 
							{name : 'operating',index : 'operating',width : 80,align : 'center',sortable:false}, 
							{name : 'eid',index : 'eid',width : 80,align : 'center',hidden:true}
							],
							//autowidth:true,
							jsonReader : {
								root : "eds",
								page : "page",
								total : "page_count",
								repeatitems : false
							},
							pager : jQuery("#entrancepage"),
							prmNames : {
								page : "page",
								sort : "sort"
							},
							rowNum : 10,
							//rowList: [10, 20, 30],
							sortname : 'teacherName',
							hidegrid : false,
							sortorder : 'asc',
							viewrecords : true,
							caption : '门禁设备信息',
							gridComplete : function() {
								var ids = jQuery("#entranceinfo").jqGrid('getDataIDs');
								for ( var i = 0; i < ids.length; i++) {
									var id = ids[i];
									ifo = "<a href='javascript:;' class='jqtrow' onclick='aeAssign("+ id+ ")'>分派</a>";
									jQuery("#entranceinfo").jqGrid('setRowData',ids[i],{operating : ifo});
								}
							}
						}).navGrid("#entrancepage", {
					edit : false,
					add : false,
					del : false,
					search : false
				});
	});
	
	
	
	function aeAssign(id){
		if (null != $("#sel_dmNmae").val()) {
			var fun = function(data) {
				if (data.s == 1) {
					$().message("分配成功");
					$("#entranceinfo").trigger("reloadGrid");
				}else{
					$().message("分配失败");
				}
			};
			exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_assign_assign${aier_suffix}"),
					fun, {
						"sid" : $("#sel_dmNmae").val(),
						"eid" : jQuery("#entranceinfo").jqGrid('getRowData', id).eid
					});
		}else{
			$().message("请先选择学校!");
		}
	}
</script>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">分派设备</a>
			</li>
		</ul>
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div class="d_scnOut" style="height: 0px;margin-top: 0px;">
					<div class="d_scname">
						<label for="t_si_region_t">选择区域:</label>
					</div>
					<div id="proxyCitiesDiv" class="sel_region"></div>
				</div>
				<div class="d_scnOut" style="margin-top: 40px;">
					<div class="d_scname">
						<label for="">选择学校:</label>
					</div>
					<div id="proxySchoolsDiv" class="sel_region"></div>
				</div>

				<div class="d_scnOut">
					<div class="d_scname">
						<label>超级管理员账号:</label>
					</div>
					<div class="d_sctext">
						<span id="span_aeAccount"></span>
					</div>
				</div>
				<div class="d_scnOut">
					<div class="d_scname">
						<label>联系电话:</label>
					</div>
					<div class="d_sctext">
						<span id="span_aePhone"></span>
					</div>
				</div>
				<div style="margin-left: 300px;margin-top: -80px;">
					<div class="d_scnOut">
						<div class="d_scname">
							<label>姓名:</label>
						</div>
						<div class="d_sctext">
							<span id="span_aeName"></span>
						</div>
					</div>
					<div class="d_scnOut">
						<div class="d_scname">
							<label>联系邮件:</label>
						</div>
						<div class="d_sctext">
							<span id="span_aeEmail"></span>
						</div>
					</div>
				</div>
				<!-- 表格 -->
				<div style="margin-top: 0px;">
					<table id="entranceinfo"></table>
					<div id="entrancepage"></div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$("#tabs").tabs();
	$(".chosen").chosen();
	loadCity();

	//查询代理下的城市集合
	function loadCity() {

		var fun = function(data) {
			if (null != data.sysCities && undefined != data.sysCities
					&& 0 < data.sysCities.length) {
				var w = "<select style='border-color: #45930b;' id='proxyCitesSel' onchange='searchSchools()'>";
				for ( var i = 0; i < data.sysCities.length; i++) {
					var proxyCities = data.sysCities[i];
					w += "<option value="+proxyCities.cid+" >"
							+ proxyCities.name + "</option>";
				}
				w += "</select>";
				$('#proxyCitiesDiv').html(w);
				searchSchools();

			} else {
				$().message("没有查询到城市!");
			}

		};
		exeAjax(
				ajaxUrl("${aier_url}proxyjs/proxy_assign_searchProxyCity${aier_suffix}"),
				fun, {
					"pid" : "${pid}"
				});

	}

	//查询已经创建的学校集合
	function searchSchools() {
		var fun = function(data) {
			if (!isnull(data.schools) && 0 < data.schools.length) {

				var temp = "<select style='border-color: #45930b;' id='sel_dmNmae' data-placeholder='请选择或输入学校名称' class='chosen' style='width:150px;' tabindex='4' onchange='searchSchoolInfo()'>";
				for ( var i = 0; i < data.schools.length; i++) {
					temp += "<option value="+data.schools[i].sid+">"
							+ data.schools[i].name + "</option>";
				}
				temp += "</select>";

				$('#proxySchoolsDiv').html(temp);
				searchSchoolInfo();
				
			} else {
				$().message("没有查询到学校!");
				$('#proxySchoolsDiv').html("");
				$("#span_aeAccount").html("");
				$("#span_aePhone").html("");
				$("#span_aeEmail").html("");
				$("#span_aeName").html("");
			}
		};
		exeAjax(
				ajaxUrl("${aier_url}proxyjs/proxy_assign_searchSchool${aier_suffix}"),
				fun, {
					"pid" : "${pid}",
					"pcid" : $("#proxyCitesSel").val()
				});

	}
	//查询学校信息
	function searchSchoolInfo() {
		var fun = function(data) {
			if (!isnull(data.schoolInfo) && 10001 == data.s) {
				$("#span_aeAccount").html(data.schoolInfo.account);
				$("#span_aePhone").html(data.schoolInfo.phone);
				$("#span_aeEmail").html(data.schoolInfo.email);
				searchNameByAccount(data.schoolInfo.account);
				
			}
		};
		exeAjax(
				ajaxUrl("${aier_url}proxyjs/proxy_assign_searchSchoolInfo${aier_suffix}"),
				fun, {
					"sid" : $("#sel_dmNmae").val()
				});

	}

	//根据用户账号取得用户姓名
	function searchNameByAccount(aeAccount) {
		var fun = function(data) {
			if (!isnull(data.aeName) && 10001 == data.s) {
				$("#span_aeName").html(data.aeName);
			}else if(10002 == data.s){
				$("#span_aeName").html("");
			}
			else if(10000 == data.s){
				$("#span_aeName").html("");
			}
		};
		exeAjax(
				ajaxUrl("${aier_url}proxyjs/proxy_assign_searchNameByAccount${aier_suffix}"),
				fun, {
					"aeAccount" : aeAccount
				});
	}
</script>
</html>